<?php
abstract class Singleton { private static $a = array(); final private function __construct() { if(array_key_exists(get_called_class(), self::$a)) { throw new Exception('Already one instance of '.get_called_class()); } static::initialize(); } abstract protected function initialize(); final public static function getInstance() { $b = get_called_class(); if(!array_key_exists($b, self::$a)) { self::$a[$b] = new $b(); } return self::$a[$b]; } final public function __clone() { throw new Exception('Class type ' . get_called_class() . ' cannot be cloned'); } }